package com.sou.technologytool.ui;

import butterknife.BindView;
import butterknife.OnClick;

import android.view.View;
import android.widget.RadioButton;
import android.widget.Toast;

import com.benben.commoncore.utils.AppManager;
import com.benben.commoncore.utils.StatusBarUtils;
import com.sou.technologytool.R;
import com.sou.technologytool.adapter.MainViewPagerAdapter;
import com.sou.technologytool.base.BaseActivity;
import com.sou.technologytool.fragment.HomeFragment;
import com.sou.technologytool.fragment.LazyBaseFragments;
import com.sou.technologytool.fragment.MineFragment;
import com.sou.technologytool.widget.NoScrollViewPager;

import java.util.ArrayList;


public class MainActivity extends BaseActivity {
    @BindView(R.id.vp_main)
    NoScrollViewPager vpMain;
    @BindView(R.id.rb_main_home)
    RadioButton rbMainHome;
    @BindView(R.id.rb_main_mine)
    RadioButton rbMainMine;

    private long mPressedTime = 0;//退出程序使用

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initData() {
        ArrayList<LazyBaseFragments> lazyBaseFragments = new ArrayList<>();
        HomeFragment homeFragment = new HomeFragment();
        MineFragment mineFragment = new MineFragment();
        lazyBaseFragments.add(homeFragment);
        lazyBaseFragments.add(mineFragment);
        vpMain.setAdapter(new MainViewPagerAdapter(getSupportFragmentManager(), lazyBaseFragments));
    }

    @OnClick({R.id.rb_main_home,  R.id.rb_main_mine})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rb_main_home:
                vpMain.setCurrentItem(0);
                StatusBarUtils.setStatusBarColor(mContext, getStatusBarColor());
                StatusBarUtils.setAndroidNativeLightStatusBar(mContext, needStatusBarDarkText());
                break;
            case R.id.rb_main_mine:
                vpMain.setCurrentItem(1);
                StatusBarUtils.setStatusBarColor(mContext, getStatusBarColor());
                StatusBarUtils.setAndroidNativeLightStatusBar(mContext, needStatusBarDarkText());
                break;
        }
    }

    @Override
    public void onBackPressed() {
        long mNowTime = System.currentTimeMillis();
        if ((mNowTime - mPressedTime) > 2000) {
            Toast.makeText(this, "Press again to exit the program", Toast.LENGTH_SHORT).show();
            mPressedTime = mNowTime;
        } else {
            AppManager.getInstance().appExit();
        }
    }

}